﻿/*  Groep 1:
*     János de Vries
*     Pelle Kersaan
*     Alex Aalbertsberg
*/ 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace SortOf
{
    class Stack<T> where T : IComparable
    {
        private ArrayList list;

        /// <summary>
        /// Represents a data collection that uses the LIFO structure.
        /// </summary>
        public Stack()
        {
            //Creates a new list.
            list = new ArrayList();
        }

        /// <summary>
        /// Returns the amount of elements in the stack.
        /// </summary>
        /// <returns>The amount of elements in the stack.</returns>
        public int Count()
        {
            return list.Count;
        }

        /// <summary>
        /// Pushes an item onto the stack.
        /// </summary>
        /// <param name="item">The item to be pushed onto the stack.</param>
        public void Push(T item)
        {
            list.Add(item);
        }

        /// <summary>
        /// Pops an item off the stack.
        /// </summary>
        /// <returns>The item that was popped off the stack</returns>
        public T Pop()
        {
            T obj = (T)list[list.Count - 1];
            list.RemoveAt(list.Count - 1);
            return obj;
        }

        /// <summary>
        /// Removes all items in the stack.
        /// </summary>
        public void Clear()
        {
            list.Clear();
        }

        /// <summary>
        /// Look at the top-most item in the stack.
        /// </summary>
        /// <returns>The top-most item in the stack.</returns>
        public T Peek()
        {
            try
            {
                return (T) list[list.Count - 1];
            }
            catch (ArgumentOutOfRangeException)
            {
                //Writes "De stack is leeg."
                Console.WriteLine("De stack is leeg.");
                return default(T);
            }
        }
    }
}